package main

import (
	"fmt"
	"log"
	"net/http"
	"sync"
)

var mu sync.Mutex
var count int

func main() {
	http.HandleFunc("/", handler3)
	http.HandleFunc("/count", counter)
	log.Fatal(http.ListenAndServe("localhost:8888", nil))
}

func counter(writer http.ResponseWriter, request *http.Request) {
	mu.Lock()
	_, _ = fmt.Fprintf(writer, "Count %d \n", count)
	mu.Unlock()
}

func handler3(w http.ResponseWriter, r *http.Request) {
	mu.Lock()
	count++
	mu.Unlock()
	_, _ = fmt.Fprintf(w, "URL Path= %q\n", r.URL.Path)
}

//留一个问题
/*访问/count 也会触发 / 的handle吗
是的,也会*/
